import { isString, isNumber, isArray, searchCover } from "@/common.js"
// 调整字段值
export const changeField = function (e, field) {
  e = e || ''
  const value = isString(e) || isNumber(e) || isArray(e) ? e : e.target.value
  // 更新右侧的值
  const item = {...this.item, [field]: value, errmsg: value.length ? '' : this.item.errmsg}
  this.$emit('setItem', item)
  // 更新整体表单的值
  let formData = searchCover(this.formData, {id: this.item.id}, v => ({...v, [field]: value, errmsg: value.length ? '' : v.errmsg}))
  formData = formData.map(v => ({...v, children: v.type == 'split' ? searchCover(v.children, {id: this.item.id}, v => ({...v, [field]: value, errmsg: value.length ? '' : v.errmsg})) : v.children}))
  this.$emit('setFormData', formData)
}
// 上传文件
export const setFileArr = function (e) {
  this.changeField(e, 'value')
}